/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			helpimpl.cc
  \date			Dec 2012
  \author		TNick

  \brief		Contains the implementation of HelpImpl class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<cpg/cpg.h>

#include	<cpg/actions/actionshost.h>
#include	<cpg/actions/editorbase.h>

#include	"helpimpl.h"
#include	"helpviewer.h"

#include	<QWhatsThis>
#include    <QMessageBox>
#include    <QMenu>


/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */


/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  DATA    ---------------------------------------------------------------- */

/*  DATA    ================================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
HelpImpl::HelpImpl		( QObject * parent )
	:QObject( parent ), MemTrack()
{
	host_ = NULL;
	vv_ = NULL;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
HelpImpl::~HelpImpl	( void )
{
	if ( vv_ != NULL )
	{
		delete vv_;
	}
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
bool						HelpImpl::init				( ActionsHost * host )
{

	host_ = host;
	ui_.setupUi( host->uiParentWidget() );
	vv_ = new HelpViewer();

	connect(ui_.action_About,   SIGNAL(triggered()), this, SLOT(slot_About()));
	connect(ui_.action_Help,    SIGNAL(triggered()), this, SLOT(slot_Help()));
	connect(ui_.action_HelpCtx, SIGNAL(triggered()), this, SLOT(slot_HelpCtx()));
	connect(ui_.action_AboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));

	ui_.action_About->setWhatsThis( ui_.action_About->toolTip() );
	ui_.action_AboutQt->setWhatsThis( ui_.action_AboutQt->toolTip() );
	ui_.action_Help->setWhatsThis( ui_.action_Help->toolTip() );
	ui_.action_HelpCtx->setWhatsThis( ui_.action_HelpCtx->toolTip() );

	ui_.action_About->setStatusTip( ui_.action_About->toolTip() );
	ui_.action_AboutQt->setStatusTip( ui_.action_AboutQt->toolTip() );
	ui_.action_Help->setStatusTip( ui_.action_Help->toolTip() );
	ui_.action_HelpCtx->setStatusTip( ui_.action_HelpCtx->toolTip() );

	ui_.action_Help->setShortcuts( QKeySequence::keyBindings( QKeySequence::HelpContents ) );
	ui_.action_HelpCtx->setShortcuts( QKeySequence::keyBindings( QKeySequence::WhatsThis ) );

	return true;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void						HelpImpl::end					( void )
{
	/* stub */
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void						HelpImpl::initMenu				( QMenu * menu )
{
	menu->addAction( ui_.action_About );
	menu->addAction( ui_.action_AboutQt );
	menu->addSeparator();
	menu->addAction( ui_.action_Help );
	menu->addAction( ui_.action_HelpCtx );

}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void        				HelpImpl::slot_About            ( void )
{
	QMessageBox::about(host_->uiParentWidget(), tr("About cad-play-ground" ),
					   tr(
						   "<h2><b>CadPlayG</b></h2>"
						   "<p>Version: " CPG_VER_STR "</p>"
						   "<p></p>"
						   "<p>This application is part of the "
						   "<b>cad-play-ground</b> package.</p>"
						   ""
						   "<p>Licence: "
						   "<a href=\"http://opensource.org/licenses/BSD-3-Clause\">"
						   "Modified (3-clause) BSD licence</a></p>"
						   ""
						   "<p>For further information visit "
						   "<a href=\"http://sites.google.com/site/cadplayground/\">"
						   "cad-play-ground site</a>.</p>"
						   ""
						   "<p>Interested in latest source code? Visit "
						   "<a href=\"https://code.google.com/p/cad-play-ground/\">"
						   "google code</a>.</p>"
						   "<p></p>"
						   "<p>This application is based on several free projects:</p>"
						   "<ul>"
						   "<li><a href=\"http://qt.nokia.com/products/\">Qt project</a></li>"
						   "<li><a href=\"http://www.mingw.org/\">MinGW on Windows</a></li>"
						   "<li><a href=\"http://www.fatcow.com/free-icons\">Fatcow icon set</a></li>"
						   "</ul>"
						   )
					   );
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void        				HelpImpl::slot_Help            	( void )
{
	vv_->showDocumentation( "CadPlayG/CadPlayG.html" );
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void        				HelpImpl::slot_HelpCtx          ( void )
{
	PGDBG2( PGDBG_A_HELP, "HelpImpl: contextual help", this );
	QWhatsThis::enterWhatsThisMode();
}
/* ========================================================================= */


/*  CLASS    =============================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
